package concurrecy;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;

class AtomicEvenGenerator extends IntGenerator {
    private AtomicInteger count = new AtomicInteger(0);

    @Override
    public int next() {
        return count.addAndGet(2);
    }
}

public class AtomicDemo {
    public static void main(String[] args) {
        IntGenerator generator = new AtomicEvenGenerator();
        ExecutorService service = Executors.newCachedThreadPool();
        for (int i = 0; i < 10; i++) {
            service.execute(new EvenChecker(generator));
        }
        service.shutdown();
    }
}
